import java.util.Scanner;

public class Demo2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String[] str1 = str.split("-");
        String[] str2 = str1[0].split(" ");
        String[] str3 = str1[1].split(" ");
        String p = "34567891JQKA2";

        if(str1[0].equals("joker JOKER") || str1[1].equals("joker JOKER")) {
            System.out.println("joker JOKER");
        }else if(str2.length == str3.length) {
            if(p.indexOf(str2[0].substring(0,1)) > p.indexOf(str3[0].substring(0,1))) {
                System.out.println(str1[0]);
            }else {
                System.out.println(str1[1]);
            }
        }else if(str2.length == 4) {
            System.out.println(str1[0]);
        }else if(str3.length == 4) {
            System.out.println(str1[1]);
        }else {
            System.out.println("ERROR");
        }
    }
}
